/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GameLogic;

import java.util.ArrayList;
import java.util.Map;

/**
 *
 * @author Ix
 */
public class TBuff implements Comparable<TBuff> {
    public String Name;
    public String Tooltip;
    public double atkSpeedMod;
    public double dmgMod;
    public double rangeMod;
    
    public TBuff(String name, double atkSpeedMod, double dmgMod, double rangeMod)
    {
        Name = name;
        this.atkSpeedMod = atkSpeedMod;
        this.dmgMod = dmgMod;
        this.rangeMod = rangeMod;
    }
    
    public void Apply(Tower t)
    {
        if(t.Buffs.containsKey(this))
            return;
        System.out.println("Added tower buff");
        t.Buffs.put(this, this);

        apply_effect(t, true);
    }
    private void apply_effect(Tower t, boolean add)
    {
        int i = -1;
        if(add)
            i = 1;
        
        //attack speed
        double cp = t.type.Cooldown / t.cooldown;
        cp += i * atkSpeedMod;
        t.cooldown = t.type.Cooldown / cp;
        
        //damage
        cp = t.MaxDamage / t.type.MaxDamage;
        cp += i * dmgMod;
        t.MinDamage = (int)(t.type.MinDamage * cp + 0.5);
        t.MaxDamage = (int)(t.type.MaxDamage * cp + 0.5);
        
        //range
        t.Range += i * rangeMod;
    }
    
    public void Remove(Tower t)
    {
        if(!t.Buffs.containsKey(this))
            return;
        //REMOVE
        t.Buffs.remove(this);
        System.out.println("Removed tower buff");
        apply_effect(t, false);
    }
    
    @Override
    public boolean equals(Object o)
    {
        return (Name == null ? ((TBuff)o).Name == null : Name.equals(((TBuff)o).Name));
    }

    @Override
    public int hashCode() {
        return Name.hashCode();
    }
    @Override
    public int compareTo(TBuff b)
    {
        return Name.compareTo(b.Name);
    }
}
